import { defHttp } from '@/utils/http/axios';
import { CertificateTemplateModel, CreateOrEditCertificateTemplateParams } from './model/certificateTemplate';
import { BasicFetchResult } from '@/api/model/baseModel'

import { ErrorMessageMode } from '#/axios';

export function getCertificateTemplateList(mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<CertificateTemplateModel>>(
    {
      url: '/connection/certificate_templates',
    },
    {
      errorMessageMode: mode
    }
  );
}

export function createCertificateTemplate(params: CreateOrEditCertificateTemplateParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post<CertificateTemplateModel>(
    {
      url: '/connection/certificate_templates',
      params
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function editCertificateTemplate(id: number, params: CreateOrEditCertificateTemplateParams, mode: ErrorMessageMode = 'message') {
  return defHttp.patch<CertificateTemplateModel>(
    {
      url: `/connection/certificate_templates/${id}`,
      params
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function deleteCertificateTemplate(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.delete(
    {
      url: `/connection/certificate_templates/${id}`,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}